package cn.jsc.quartz.service.impl;

import cn.jsc.quartz.dto.QuartzJobInfo;
import cn.jsc.quartz.job.MainJob;
import cn.jsc.quartz.service.IQuartzService;
import cn.jsc.quartz.util.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

/**
 * 注意：传递的时候要传递整个info
 */
@Service
public class QuartzServiceImpl implements IQuartzService {
    //springboot做了自动配置 - 直接注入进来使用即可
    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void add(QuartzJobInfo info) {
        //调用工具类添加定时任务：传参数的时候要传递info：拿的时候：1.type 2.数据orderId
        QuartzUtils.addJob(factoryBean.getScheduler(),
                info.getJobName(),
                MainJob.class,
                info,
                info.getCronj());
    }

    @Override
    public void remove(String jobName) {//type + paySn
        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);

    }
}
